
/*
 * @Description: 
 * @Author: rendc
 * @Date: 2024-10-16 17:17:58
 * @LastEditors: rendc
 * @LastEditTime: 2024-10-16 17:41:09
 */
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * Test01Client - 客户端代码
 */
public class Test02Client {

  public static void main(String[] args) throws Exception {
    // 创建一个Socket对象准备连接服务器
    Socket socket = new Socket("127.0.0.1", 8989);
    // 获取IO流对象
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    System.out.println("连接服务器成功");
    // 获取用户输入，发送给服务器
    // Scanner sc = new Scanner(System.in);
    String userInput = reader.readLine();
    System.out.println("userInput:" + userInput);
    // 发送消息到服务器
    out.println(userInput);
    // 断开连接
    in.close();
    out.close();
    reader.close();
    socket.close();
  }
}